package dwz.web.management.lotto;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import dwz.business.lotto.QiHaoInterface;
import dwz.business.lotto.YongHuInterface;
import dwz.common.util.MD5Util;
import dwz.persistence.beans.QiHao;
import dwz.persistence.beans.YongHu;
import dwz.persistence.beans.YongHuExample;
import dwz.web.BaseController;
/**
 * 
 * 前台用户相关的action
 *
 */
@Controller
@RequestMapping(value="/management/yonghu")
public class YongHuAction extends BaseController{
	@Autowired
	YongHuInterface yongHuInterface;
	@Autowired
	QiHaoInterface qiHaoInterface;
	
	
	
	
	
	/**
	 *  用户账户信息 对应主页左侧的那一小块区域
	 * @return
	 */
	@RequestMapping("/huiyuanxinxi")
	public String yonghuxingxi(Model model,HttpServletRequest request){
		/**
		 * 还有个期号 那么最好是放到登录信息中
		 */
		
		YongHu yongHu = yongHuInterface.selectByPrimaryKey((Integer) request.getSession().getAttribute(CommonFields.USERID));
		model.addAttribute("user", yongHu);
		QiHao qiHao = qiHaoInterface.selectMaxQiHao();
		Integer latestQihao = qiHao.getQh_j();
		model.addAttribute("qihao", latestQihao);
		request.getSession().setAttribute(CommonFields.QIHAO, latestQihao);
		return "/management/front/huiyuanxinxi";
	}
	/**
	 * 跳转到修改密码页面
	 * @return
	 */
	@RequestMapping("/xiugaimima")
	public String xiugaimima(){
		return "/management/front/xiugaimima";
	}
	
	/**
	 * 修改密码
	 * @return
	 */
	@RequestMapping("/xiugaimima2")
	public  String xiugaimima2(HttpServletRequest request,Model model){
		String tootip  = yongHuInterface.modifyPassword((Integer)request.getSession().getAttribute(CommonFields.USERID), request.getParameter("oldPassword"), request.getParameter("newPassword"));
		
		if(tootip.equals("修改密码成功")){
			return "redirect:/management/yonghu/logout";
		}
		model.addAttribute("tooltip", tootip);
		return "/management/front/xiugaimima";
	}
	
	
	@RequestMapping("/logout")
	public  String logout(HttpServletRequest request){
		request.getSession().invalidate();
		return "redirect:/front";
	}
	
	
	
	@RequestMapping("/xiugaichenggong")
	public String xiugaichenggong(HttpServletRequest request){
		YongHu yonghu = new YongHu();
		yonghu.setId(1);
		yonghu.setMm_j(request.getParameter("newPassword"));
		yongHuInterface.updateByPrimaryKeySelective(yonghu);
		return "/management/front/shengchengkuang";
	}
	/**
	 * 跳转到顶部
	 * @param request
	 * @return
	 */
	@RequestMapping("/top")
	public String top(HttpServletRequest request){
		return "/management/front/top";
	}

}
